package com.wgh.product.service.impl;

import com.wgh.product.entity.shop.ProductAttribute;
import com.wgh.product.mapper.ProductAttributeMapper;
import com.wgh.product.service.ProductAttributeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品属性Service实现类
 * 
 * @author AI Shop
 */
@Service
public class ProductAttributeServiceImpl extends ServiceImpl<ProductAttributeMapper, ProductAttribute> implements ProductAttributeService {

    @Override
    public List<ProductAttribute> getAttributesByCategoryId(Long categoryId) {
        return baseMapper.selectByCategoryId(categoryId);
    }

    @Override
    public List<ProductAttribute> getAttributesByCategoryIds(List<Long> categoryIds) {
        return baseMapper.selectByCategoryIds(categoryIds);
    }

    @Override
    public boolean checkAttributeExists(String name, Long categoryId) {
        return baseMapper.countByNameAndCategoryId(name, categoryId) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteBatch(List<Long> ids) {
        return baseMapper.deleteBatch(ids) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateStatusBatch(List<Long> ids, Integer status) {
        return baseMapper.updateStatusBatch(ids, status) > 0;
    }

    @Override
    public List<ProductAttribute> getAttributePage(String keyword, Long categoryId, Integer pageNum, Integer pageSize) {
        Integer start = (pageNum - 1) * pageSize;
        return baseMapper.selectPage(keyword, categoryId, start, pageSize);
    }
}